﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InstaGM
{
    public partial class misc_settings : Form
    {
        public misc_settings()
        {
            InitializeComponent();
            items_to_itembox.Click += warn_user;
            ToolTip tooltip = new ToolTip();
            tooltip.ToolTipIcon = ToolTipIcon.Info;
            tooltip.ToolTipTitle = "Information";
            tooltip.IsBalloon = true;
            tooltip.ShowAlways = true;
            tooltip.SetToolTip(to_itembox_q, "Checking this option will tell InstaGM that you want Items to be sent to selected players Item Box.");
            tooltip.SetToolTip(to_clipboard_q, "Checking this option will tell InstaGM that you want Items to be sent to your Clip Board.");
            tooltip.SetToolTip(always_to_itembox_q, "Checking this option will tell InstaGM you always want Summons/Items sent to the selected players Item Box");
            tooltip.SetToolTip(always_to_clipboard_q, "Checking this option will tell InstaGM you always want Summons/Items sent to your Clip Board");
            tooltip.SetToolTip(always_to_telnet_q, "Checking this option will tell InstaGM you always want all Telnet enabled commands sent to Telnet");
            tooltip.SetToolTip(to_telnet_q, "Checking this option will tell InstaGM you want States to be sent via Telnet");
            tooltip.SetToolTip(state_to_clipboard_q, "Checking this option will tell InstaGM you want Buffs to be sent to your Clip Board");
            tooltip.SetToolTip(spawns_to_telnet_q, "Checking this option will tell InstaGM you always want spawns sent to the Telnet");
            tooltip.SetToolTip(spawns_to_clipboard_q, "Checking this option will tell InstaGM you always want spawns sent to the Clip Board");
            add_control_event();
        }

        public void warn_user(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.item_to_itembox_warning == false)
            {
                if (MessageBox.Show("By checking this box you acknowledge that InstaGM will connect to your database using the above connection information!\n\n If you do not want this, press CANCEL!\n\n NOTICE: It is recommended to follow the below guide before using this feature: http://goo.gl/z4sm0 \n\nTealSky is not responsible for improper security precations and or your giving this tool to people you don't absolutely trust!!!", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                {
                    items_to_itembox.Checked = true;
                    Properties.Settings.Default.item_to_itembox = true;
                    Properties.Settings.Default.item_to_itembox_warning = true;
                    Properties.Settings.Default.Save();

                    if (items_to_clipboard.Checked == true)
                    {
                        items_to_clipboard.Checked = false;
                    }
                }
                else
                {
                    items_to_itembox.Checked = false;
                    Properties.Settings.Default.item_to_itembox = false;
                    Properties.Settings.Default.Save();
                }
            }
        }

        public void misc_settings_Load(object sender, EventArgs e)
        {
            auto_tamed.Checked = Properties.Settings.Default.auto_tamed;
            always_to_itembox.Checked = Properties.Settings.Default.always_to_itembox;
            always_to_clipboard.Checked = Properties.Settings.Default.always_to_clipboard;
            always_to_telnet.Checked = Properties.Settings.Default.always_to_telnet;
            items_to_itembox.Checked = Properties.Settings.Default.item_to_itembox;
            items_to_clipboard.Checked = Properties.Settings.Default.item_to_clipboard;
            to_telnet.Checked = Properties.Settings.Default.to_telnet;
            state_to_clipboard.Checked = Properties.Settings.Default.state_to_clipboard;
            player_to_telnet.Checked = Properties.Settings.Default.player_to_telnet;
            player_to_clipboard.Checked = Properties.Settings.Default.player_to_clipboard;
            spawn_to_telnet.Checked = Properties.Settings.Default.spawns_to_telnet;
            spawn_to_clipboard.Checked = Properties.Settings.Default.state_to_clipboard;
        }

        public void add_control_event()
        {
            always_to_itembox.Click += alter_from_always_item;
            always_to_clipboard.Click += alter_from_always_clipboard;
            always_to_telnet.Click += alter_from_always_telnet;
            items_to_itembox.Click += alter_iSettings; ;
            items_to_clipboard.Click += alter_cSettings;
            player_to_telnet.Click += alter_ptSettings;
            player_to_clipboard.Click += alter_pcSettings;
            to_telnet.Click += alter_stSettings;
            state_to_clipboard.Click += alter_scSettings;
            spawn_to_telnet.Click += alter_ttSettings;
            spawn_to_clipboard.Click += alter_tcSettings;
        }

        public void alter_from_always_item(object sender, EventArgs e)
        {
            if (always_to_telnet.Checked == true)
            {
                //We should unset them both at this point because either or's rule is non-applicable now
                always_to_telnet.Checked = false;
            }

            items_to_clipboard.Checked = false;
            

            if (always_to_itembox.Checked == true)
            {
                always_to_itembox.Checked = true;
                items_to_itembox.Checked = true;
            }
            else
            {
                always_to_itembox.Checked = false;
                items_to_itembox.Checked = false;
            }
        }

        public void alter_iSettings(object sender, EventArgs e)
        {
            if (always_to_clipboard.Checked == true)
            {
                always_to_clipboard.Checked = false;
                items_to_clipboard.Checked = false;
                state_to_clipboard.Checked = false;
            }
        }

        public void alter_from_always_clipboard(object sender, EventArgs e)
        {
            //Unselect always to telnet
            always_to_telnet.Checked = false;
            //Uncheck all Telnet Boxes
            player_to_telnet.Checked = false;
            to_telnet.Checked = false;
            spawn_to_telnet.Checked = false;
            //Unselect always to itembox
            always_to_itembox.Checked = false;
            //Uncheck all to ItemBox Boxes
            items_to_itembox.Checked = false;
            //Check all clipboard boxes
            player_to_clipboard.Checked = true;
            items_to_clipboard.Checked = true;
            state_to_clipboard.Checked = true;
            spawn_to_clipboard.Checked = true;
        }

        public void alter_cSettings(object sender, EventArgs e)
        {
            if (always_to_itembox.Checked == true)
            {
                always_to_itembox.Checked = false;
                items_to_itembox.Checked = false;
            }
            items_to_itembox.Checked = false;
            items_to_clipboard.Checked = true;
        }

        public void alter_ptSettings(object sender, EventArgs e)
        {
            //If one of the opposing settings is there remove him
            if (always_to_clipboard.Checked == true || always_to_itembox.Checked == true)
            {
                //We should unset them both at this point because either or's rule is non-applicable now
                always_to_itembox.Checked = false;
                always_to_clipboard.Checked = false;
            }

            if (player_to_clipboard.Checked == true)
            {
                player_to_clipboard.Checked = false;
            }
        }

        public void alter_pcSettings(object sender, EventArgs e)
        {
            //If one of the opposing settings is there remove him
            if (always_to_clipboard.Checked == true || always_to_telnet.Checked == true)
            {
                //We should unset them both at this point because either or's rule is non-applicable now
                always_to_itembox.Checked = false;
                always_to_telnet.Checked = false;
            }

            if (player_to_telnet.Checked == true)
            {
                player_to_telnet.Checked = false;
            }
        }

        public void alter_from_always_telnet(object sender, EventArgs e)
        {
            //First we should blank any clipboard preferences
            player_to_clipboard.Checked = false;
            items_to_clipboard.Checked = false;
            state_to_clipboard.Checked = false;
            spawn_to_clipboard.Checked = false;
            always_to_clipboard.Checked = false;
            always_to_itembox.Checked = false;
            
            //Now let's check all the "Telnet" boxes
            player_to_telnet.Checked = true;
            to_telnet.Checked = true;
            spawn_to_telnet.Checked = true;
        }

        //When the "Spawn Telnet" setting is activated
        public void alter_ttSettings(object sender, EventArgs e)
        {
            if (spawn_to_clipboard.Checked == true)
            {
                spawn_to_clipboard.Checked = false;
            }
        }

        //When the "Spawn Clipboard" setting is activated
        public void alter_tcSettings(object sender, EventArgs e)
        {
            if (spawn_to_telnet.Checked == true)
            {
                spawn_to_telnet.Checked = false;
            }
        }

        //When the "State Telnet" setting is activated
        public void alter_stSettings(object sender, EventArgs e)
        {
            //If one of the opposing settings is there remove him
            if (always_to_clipboard.Checked == true || always_to_itembox.Checked == true)
            {
                //We should unset them both at this point because either or's rule is non-applicable now
                always_to_itembox.Checked = false;
                always_to_clipboard.Checked = false;
            }

            //If State to Clipboard is checked, uncheck him
            if (state_to_clipboard.Checked == true)
            {
                state_to_clipboard.Checked = false;
            }
        }

        //When the "State Clipboard" setting is activated
        public void alter_scSettings(object sender, EventArgs e)
        {
            //If one of the opposing settings is there remove him
            if (always_to_clipboard.Checked == true || always_to_itembox.Checked == true)
            {
                //We should unset them both at this point because either or's rule is non-applicable now
                always_to_itembox.Checked = false;
                always_to_telnet.Checked = false;
            }
            //If State to Telnet is checked unset it
            if (to_telnet.Checked == true)
            {
                to_telnet.Checked = false;
            }
        }
        
        //Save Button has been pressed
        private void instagm_misc_setting_save_Click(object sender, EventArgs e)
        {
            //If Auto Tamed has been checked
            if (auto_tamed.Checked == true)
            {
                Properties.Settings.Default.auto_tamed = true;
            }
            else
            {
                Properties.Settings.Default.auto_tamed = false;
            }
            //If Always to Itembox has been checked
            if (always_to_itembox.Checked == true)
            {
                Properties.Settings.Default.always_to_itembox = true;
                Properties.Settings.Default.item_to_itembox = true;
            }
            else
            {
                Properties.Settings.Default.always_to_itembox = false;
            }
            //If Always to Clipboard has been checked
            if (always_to_clipboard.Checked == true)
            {
                Properties.Settings.Default.always_to_clipboard = true;
                Properties.Settings.Default.item_to_clipboard = true;
                Properties.Settings.Default.state_to_clipboard = true;
            }
            else
            {
                Properties.Settings.Default.always_to_clipboard = false;
            }
            //If Always to Telnet has been checked
            if (always_to_telnet.Checked == true)
            {
                Properties.Settings.Default.player_to_telnet = true;
                Properties.Settings.Default.to_telnet = true;
                Properties.Settings.Default.spawns_to_telnet = true;
            }
            if (items_to_itembox.Checked == true)
            {
                Properties.Settings.Default.item_to_itembox = true;
            }
            else
            {
                Properties.Settings.Default.item_to_itembox = false;
            }
            if (items_to_clipboard.Checked == true)
            {
                Properties.Settings.Default.item_to_clipboard = true;
            }
            else
            {
                Properties.Settings.Default.item_to_clipboard = false;
            }
            if (to_telnet.Checked == true)
            {
                Properties.Settings.Default.to_telnet = true;
            }
            else
            {
                Properties.Settings.Default.to_telnet = false;
            }
            if (state_to_clipboard.Checked == true)
            {
                Properties.Settings.Default.state_to_clipboard = true;
            }
            else
            {
                Properties.Settings.Default.state_to_clipboard = false;
            }
            if (player_to_telnet.Checked == true)
            {
                Properties.Settings.Default.player_to_telnet = true;
            }
            else
            {
                Properties.Settings.Default.player_to_telnet = false;
            }
            if (player_to_clipboard.Checked == true)
            {
                Properties.Settings.Default.player_to_clipboard = true;
            }
            else
            {
                Properties.Settings.Default.player_to_clipboard = false;
            }
            if (spawn_to_telnet.Checked == true)
            {
                Properties.Settings.Default.spawns_to_telnet = true;
            }
            else
            {
                Properties.Settings.Default.spawns_to_telnet = false;
            }
            if (spawn_to_clipboard.Checked == true)
            {
                Properties.Settings.Default.spawns_to_clipboard = true;
            }
            else
            {
                Properties.Settings.Default.spawns_to_clipboard = false;
            }
            Properties.Settings.Default.Save();
            Application.Restart();
        }
    
    }
}
